<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 12:26
 */

/**
 * Class Involved_ReceiveAddressModel
 */

class Involved_AddressModel extends BaseModel{

    protected $table = 'address';


    /**
     * 获取收货地址信息
     * @param $user_id
     * @param $address_id
     * @return array
     */
    public function GetAddress($user_id,$address_id)
    {
        $info =  DB::table($this->table)
              ->select('consignee','address','mobile','address_all')
              ->where(['user_id'=>$user_id,'address_id'=>$address_id])
              ->first();

        $data = [
            'consignee'         => $info->consignee,
            'address'           => $info->address,
            'mobile'            => $info->mobile,
            'address_all'       => $info->address_all,
        ];
        return $data;
    }

    /**
     * 获取收货地址列表
     * @param $user_id
     * @return mixed
     */
    public function GetAddressList($user_id)
    {
        return  DB::table($this->table)
            ->select('address_id','consignee','address','mobile','is_default','address_all')
            ->where(['user_id' => $user_id])
            ->where('status','!=',0)
            ->orderBy('is_default','desc')
            ->orderBy('address_id','desc')
            ->get();
    }



    /**
     * 删除收货地址
     * @param $paramObj
     * @return mixed
     */
    public function DeleteAddress($paramObj)
    {
        return DB::table($this->table)->where(['address_id' => $paramObj->address_id])->delete();
    }


    /**
     * @param $user_id
     * @return mixed
     * 获取默认收货地址详情
     */
    public function GetAddressDefault($user_id)
    {
        return DB::table($this->table)
                ->select('address_id','consignee','mobile','address','address_all')
                ->where(['is_default'=>UserEnum::CLIENT_USER_DEFAULT_ADDRESS,'user_id'=>$user_id])
                ->first();
    }

    /**
     * @param $user_id
     * @return mixed
     * 获取一条收货地址详情
     */
    public function GetOneAddress($user_id)
    {
        return DB::table($this->table)
            ->select('address_id','consignee','mobile','address','address_all')
            ->where('user_id',$user_id)
            ->where('status','!=',0)
            ->orderBy('is_default','desc')
            ->orderBy('address_id','desc')
            ->first();
    }
    public function GetOrderAddress($address_id)
    {
        return  DB::table($this->table)
            ->select('address_id','consignee','mobile','address','address_all')
            ->where(['address_id'=>$address_id])
            ->get();
    }
    public function UpdateSelect($address_id)
    {
        return DB::table($this->table)
            ->select('address_id','consignee','mobile','address','address_all')
            ->where('address_id',$address_id)
            ->first();
    }













}